﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Slja.Lib
{
    public class Utility
    {   
        /// <summary>
        /// 转化出易读的文件大小（如 1.5M、0.6K）
        /// </summary>
        /// <param name="fileLen">字节大小</param>
        /// <returns></returns>
        public static string ConvertFileLength(decimal fileLen)
        {
            Char[] chUnit = new Char[4] { 'K', 'M', 'G', 'T' };
            string strSize = "";
            char unit;
            int n = 0;
            do
            {
                fileLen /= 1024;
                unit = chUnit[n++];                
            } while (fileLen >= 1000);
            fileLen = Math.Round(fileLen, 1);
            strSize = fileLen.ToString() + unit;
            return strSize;
        }
    }
}
